var util = require('../../utils/util.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    height: "100%",
    hunterInfo:{},
    adviseProId:null,
    ordeschangeInfo:{}, 
    ordesupInfo:{},
    ordesalaryInfo:{},
    ordeleaveInfo:{},
    avatarUrl: '/images/default_avatar.png',
    userInfo: '',
    showEvalute: [],
    showArt:{},
    isHaveResume: null,
    nonet: true ,
    isPaySalary:0,
    itemName: "",
    radioValue:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    // console.log(JSON.parse(options.hunter));
    // console.log(JSON.parse(options.adviseProId));
    that.setData({
      hunterInfo: JSON.parse(options.hunter),
      adviseProId: options.adviseProId,
      itemName: options.adviseProName,
      radioValue: JSON.parse(options.adviseProId) == undefined ? null : options.adviseProId
    });
    // console.log("options.adviseProI: " + options.adviseProI);
    // console.log(JSON.parse(options.adviseProId) == undefined);
    
    wx.setNavigationBarTitle({
      title: that.data.hunterInfo.name + "顾问"//页面标题为路由参数
    })
    util.post(app.api.getOrderDescList, { hunterid: that.data.hunterInfo.id  }, function (res) {
      console.log(res.data);
      var msg = res.msg;
      var change = res.data.change
      var interview = res.data.interview
      var up = res.data.up
      var salary = res.data.salary
      var leave = res.data.leave
      if (msg == 5) {
        that.setData({
          ordeschangeInfo: change,
          ordesinterviewInfo: interview,
          ordesupInfo: up,
          ordesalaryInfo: salary,
          ordeleaveInfo: leave
        });
      } else if (msg == 4) {
        that.setData({
          ordeschangeInfo: change,
          ordesinterviewInfo: interview,
          ordesupInfo: up,
          ordesalaryInfo: salary
        });
      } else if (msg == 3) {
        that.setData({
          ordeschangeInfo: change,
          ordesinterviewInfo: interview,
          ordesupInfo: up
        });
      } else if (msg == 2) {
        that.setData({
          ordeschangeInfo: change,
          ordesinterviewInfo: interview
        });
      } else if (msg == 1) {
        that.setData({
          ordeschangeInfo: change
        });
      }
    });

  },
  radioChange:function(event){
    var that = this;
    var radioValue = event.detail.value;
    this.setData({
      radioValue:event.detail.value
    })
    console.log("radioValue=" + radioValue);
    util.post(app.api.getOrderDescId, { oritemid: radioValue }, function (res) {
      console.log("已选的咨询项目" + res.data);
      that.setData({
        iteminfo: res.data,
        adviseProId: radioValue,
        itemName: res.data.name
      });
    });
  },
  isSendTap: function (event) {
    if(!this.data.radioValue){
      wx.showToast({
        title: '请先选择您需咨询的项目',
        icon: 'none'
      })
      return false
    }
    var that = this;
    console.log("check service" + that.data.radioPro);
    util.post(app.api.isPaySalaryItem, { openid: app.globalData.openid }, function (res) {
      console.log("已选的咨询项目" + res.data);
      that.setData({
        isPaySalary: res.data,
      });
    });
    console.log("that.data.isPaySalary:" + that.data.isPaySalary);
    console.log("that.data.itemName:" + that.data.itemName);
    if (that.data.itemName.indexOf("薪资谈判")>-1 && that.data.isPaySalary==0){
    app.alert("因薪资谈判服务需提前收集您的相关资料及制定总体薪酬方案，需加上总体薪酬分析及合理化建议服务（建议在offer流程中的候选人选择此项目）");
    }else{
      if (that.data.adviseProId!=null){
        // 切换页面
        wx.navigateTo({
          url: '../hunter-ordertime/hunter-ordertime?hunter=' + JSON.stringify(that.data.hunterInfo) + '&adviseProId=' + that.data.adviseProId
        });
      }
    }
   
  },

  //关闭成功提示
  closeTap: function () {
    this.setData({
      mode: true,
      height: "100%"
    })
  },


  //分享
  onShareAppMessage: function (res) {
    var that = this;
    console.log(that.data.hunterInfo);
    if (res.from === 'button') {
      // 来自页面内转发按钮
      // console.log(res.target)
    }
    var title = that.data.hunterInfo.name + ' 职业经纪人 ' + that.data.hunterInfo.workage +'年'+ '【' + that.data.hunterInfo.bestdomain + '】';
    return {
      title: title,
      path: 'pages/hunter-detail/hunter-detail?hunterid=' + that.data.hunterInfo.id,
      data: that.data.hunterInfo,
      success: function (res) {
        // 转发成功
        // console.log(res);
      },
      fail: function (res) {
        console.log(res)
        // 转发失败
      }
    }
  },
  onShow:function(){
    var that = this;
    wx.getNetworkType({
      success: function (res) {
        // 返回网络类型, 有效值：
        // wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
        var networkType = res.networkType
        console.log("networkType=" + networkType);
        if (networkType == "none") {
          that.setData({
            nonet: false,
            submitdisabled: true
          })
        }
      }
    })
  }
})